import { defineStore } from "pinia";
import { getProductList, getProductDetail } from "@/api/product"; // 引入api

export const useProductStore = defineStore("product", {
  state: () => ({
    list: [],
    currentDetail: null,
    loading: false,
  }),
  actions: {
    // 加载商品列表（调用api并更新状态）
    async loadProductList(params) {
      this.loading = true;
      try {
        const data = await getProductList(params);
        this.list = data;
      } finally {
        this.loading = false;
      }
    },
    // 加载商品详情
    async loadProductDetail(id) {
      this.loading = true;
      try {
        this.currentDetail = await getProductDetail(id);
      } finally {
        this.loading = false;
      }
    },
  },
});
